package com.truckdispatching.http.controller;

import java.util.HashMap;

import org.json.JSONObject;

import com.truckdispatching.UserManager;
import com.truckdispatching.http.util.TDHttpController;

/**
 * 获取卡车图片
 * 
 * @author Lee
 * @date 2013-5-12
 */
public class GetPhotosHttpController extends TDHttpController {

	@Override
	public String getRequestUrl() {
		return mHostUrl + "/wap/getPhotos.do";
	}

	public void sendRequest() {
		HashMap<String, String> params = new HashMap<String, String>();
		params.put("jsessionid", UserManager.getToken());
		sendRequest(params, false);
	}

	@Override
	public void onSuccess(String response) {
		try {
			JSONObject jo = getJSONObjectFromJSON(new JSONObject(response), "data", null);
			UserManager.setPicIDCard(getStringFromJSON(jo, "idcPhoto", ""));
			UserManager.setPicDrivingLicence(getStringFromJSON(jo, "dcPhoto", ""));
			UserManager.setPicTravelLicence(getStringFromJSON(jo, "vtcPhoto", ""));
			UserManager.setPicTruckHead(getStringFromJSON(jo, "thPhoto", ""));
			UserManager.setPicTruckBack(getStringFromJSON(jo, "ttPhoto", ""));
			UserManager.setPicTruckSideFace(getStringFromJSON(jo, "tsPhoto", ""));
			callOnResponseListener(null);
		} catch (Exception e) {
			callOnResponseErrorListener(-1, "JSON数据异常");
		}
	}

	@Override
	public void onError(int errorCode, String errorMessage) {
		callOnResponseErrorListener(errorCode, errorMessage);
	}
}
